// Copyright Epic Games, Inc. All Rights Reserved.

#include "LocalConfigBPLibrary.h"
#include "LocalConfig.h"

ULocalConfigBPLibrary::ULocalConfigBPLibrary(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{

}

float ULocalConfigBPLibrary::LocalConfigSampleFunction(float Param)
{
	return -1;
}

FString ULocalConfigBPLibrary::GetProjectDir()
{
	FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::GameSourceDir());
	return ThePath;
}
FString ULocalConfigBPLibrary::GetPakRootDir()
{
	FString ThePath = FPaths::ConvertRelativePathToFull(FPaths::RootDir());
	return ThePath;
}
bool ULocalConfigBPLibrary::SaveTextArray(FString FileName, TArray<FString> TextArray, bool OverWrite)
{
	FString Directory = GetProjectDir();
	Directory += FileName;
	if (OverWrite) {
		if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*Directory)) {
			return false;
		}
	}
	return FFileHelper::SaveStringArrayToFile(TextArray, *Directory);
}

TArray<FString> ULocalConfigBPLibrary::ReadTxt(FString FileName, bool IsPackage)
{
	TArray<FString> strArray;
	FString Directory = IsPackage? GetPakRootDir() :GetProjectDir();
	Directory += FileName;
	if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*Directory))
	{
				FFileHelper::LoadFileToStringArray(strArray, *Directory);
	}
	return strArray;
}

